using UnityEngine;

namespace Exploder.Demo
{
	public class ExploderMouseLook : MonoBehaviour
	{
		public enum RotationAxes
		{
			MouseXAndY,
			MouseX,
			MouseY
		}

		public RotationAxes axes;

		public float sensitivityX = 15f;

		public float sensitivityY = 15f;

		public float minimumX = -360f;

		public float maximumX = 360f;

		public float minimumY = -60f;

		public float maximumY = 60f;

		private float rotationY;

		private float kickTimeout;

		private float kickBackRot;

		private bool kickBack;

		private float rotationTarget;

		public Camera mainCamera;

		private void Update()
		{
			if (!CursorLocking.IsLocked)
			{
				return;
			}
			float num = 0f;
			if (axes == RotationAxes.MouseXAndY)
			{
				Vector3 localEulerAngles = base.transform.localEulerAngles;
				float num2 = localEulerAngles.y + UnityEngine.Input.GetAxis("Mouse X") * sensitivityX;
				rotationY += UnityEngine.Input.GetAxis("Mouse Y") * sensitivityY;
				rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
				num = num2;
				mainCamera.transform.localEulerAngles = new Vector3(0f - rotationY, 0f, 0f);
				if (kickTimeout > 0f)
				{
					rotationTarget += UnityEngine.Input.GetAxis("Mouse Y") * sensitivityY;
				}
			}
			else if (axes == RotationAxes.MouseX)
			{
				num = UnityEngine.Input.GetAxis("Mouse X") * sensitivityX;
				mainCamera.transform.Rotate(0f, 0f, 0f);
			}
			else
			{
				rotationY += UnityEngine.Input.GetAxis("Mouse Y") * sensitivityY;
				rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
				if (kickTimeout > 0f)
				{
					rotationTarget += UnityEngine.Input.GetAxis("Mouse Y") * sensitivityY;
				}
				Vector3 localEulerAngles2 = base.transform.localEulerAngles;
				num = localEulerAngles2.y;
				mainCamera.transform.localEulerAngles = new Vector3(0f - rotationY, 0f, 0f);
			}
			kickTimeout -= Time.deltaTime;
			if (kickTimeout > 0f)
			{
				rotationY = Mathf.Lerp(rotationY, rotationTarget, Time.deltaTime * 10f);
			}
			else if (kickBack)
			{
				kickBack = false;
				kickTimeout = 0.5f;
				rotationTarget = kickBackRot;
			}
			base.gameObject.transform.rotation = Quaternion.Euler(0f, num, 0f);
		}

		private void Start()
		{
			if ((bool)GetComponent<Rigidbody>())
			{
				GetComponent<Rigidbody>().freezeRotation = true;
			}
		}

		public void Kick()
		{
			kickTimeout = 0.1f;
			rotationTarget = rotationY + (float)UnityEngine.Random.Range(15, 20);
			kickBackRot = rotationY;
			kickBack = true;
		}
	}
}
